﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel; 

namespace InscriberControlClient
{
    /// <summary>
    /// Interaction logic for Window2.xaml
    /// </summary>
    /// 
  

   

    public partial class Window2 : Window
    {
        public ObservableCollection<Lydai> ld;
        public static bool isMove = false;

        public Window2()
        {
            InitializeComponent();
            /*  ld = new ObservableCollection<Lydai>() {
                  new Lydai() { nr=1, Title = "Tim"},
                  new Lydai() { nr=2, Title = "Marc" },
                  new Lydai() { nr=3, Title = "Ann" },
                  new Lydai() { nr=4, Title = "Jan" },
                  new Lydai() { nr=5, Title="ddd" },
                  new Lydai() { nr=6, Title = "Marc" },
                  new Lydai() { nr=7, Title = "Ann" },
                  new Lydai() { nr=8, Title = "Jan" },
                  new Lydai() { nr=9, Title="ddd" },
                  new Lydai() { nr=10, Title = "Marc" },
                  new Lydai() { nr=11, Title = "Ann" },
                  new Lydai() { nr=12, Title = "Jan" },
                  new Lydai() { nr=13, Title="ddd" }
              };*/

            peopleListBox.DataContext = ld;

        }

        private void Button_Click1(object sender, RoutedEventArgs e)
        {
            ld = Functionality.getLydai("");
            peopleListBox.DataContext = ld;
        }

        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        private void cmdRunLD_Clicked(object sender, RoutedEventArgs e)
        {

            Button cmd = (Button)sender;
            if (cmd.DataContext is Lydai)
            {

                Lydai item = (Lydai)cmd.DataContext;
                Functionality.startLDloop(item.nr.ToString(), false);
                //MessageBox.Show(item.nr.ToString());
                //ld.Remove(deleteme);

            }

        }

        private void cmdRunLDintro_Clicked(object sender, RoutedEventArgs e)
        {

            Button cmd = (Button)sender;
            if (cmd.DataContext is Lydai)
            {

                Lydai item = (Lydai)cmd.DataContext;
                Functionality.startLDintro(item.nr.ToString(), item.Type);
                //MessageBox.Show(item.nr.ToString());
                //ld.Remove(deleteme);

            }

        }

        private void cmdStopLD_Clicked(object sender, RoutedEventArgs e)
        {

            Button cmd = (Button)sender;
            if (cmd.DataContext is Lydai)
            {

                Lydai item = (Lydai)cmd.DataContext;
                Functionality.stopLD(item.Type);
                //MessageBox.Show(item.nr.ToString());
                //ld.Remove(deleteme);

            }

        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
           /* if (e.LeftButton == MouseButtonState.Pressed)
            {
                System.Windows.Point pt = Mouse.GetPosition(Application.Current.MainWindow);
                Functionality.DragMoveNew(this, e, pt);
            }*/
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox ch=(CheckBox)sender;
            string id = ch.Tag.ToString();
            if (ch.IsChecked == true)
            {
                Functionality.updateLeadTemplateToKById(id);
            }
            else
            {
                Functionality.updateLeadTemplateToNById(id);
            }
            ld = Functionality.getLydai("X");
            peopleListBox.DataContext = ld;
        }

        private void CheckBox_TargetUpdated(object sender, DataTransferEventArgs e)
        {
            CheckBox ch = (CheckBox)sender;
            string temp = ch.ToolTip.ToString();
            if (temp.Equals('K'))
            {
                ch.IsChecked = true;
            }
            else if (temp.Equals('N'))
            {
                ch.IsChecked = false;
            }
        }

        private void CheckBox_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
        {
         }

        private void peopleListBox_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
        
        }

        private void peopleListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
           /* isMove = true;
            Functionality.lastPosition = Mouse.GetPosition(this);*/
        }

        private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            isMove = false;
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            /*if (isMove)
            {
                System.Windows.Point pt = Mouse.GetPosition(this);
                Functionality.DragMoveNew(this, e, pt);
            }*/
        }

        private void Window_MouseLeave(object sender, MouseEventArgs e)
        {
            isMove = false;
        }
    }
}
